<template>
  <div class="approval-manage-main">
    <div class="main-title">
      <div>
        <span @click="handleTitle(true)" :class="{ 'type-active': flag }"
          >工单记录 &nbsp;|&nbsp;</span
        ><span @click="handleTitle(false)" :class="{ 'type-active': !flag }"
          >待办事项</span
        >
      </div>
    </div>
    <!-- <el-button type="text" class="operate" @click="goPage"
        >更多<i class="el-icon-arrow-right"></i
      ></el-button> -->
    <div class="manage-main-content" v-loading="loading">
      <template v-if="instanceList.length">
        <div
          v-for="item in instanceList"
          :key="item.id"
          @click="toDetails(item)"
        >
          <div class="content-item">
            <div :class="addClass(item.status)">{{ item.statusToString }}</div>
            <span
              >{{ item.name || item.processInstanceName
              }}{{ item.statusToString }}</span
            >
          </div>
          <!-- <div class="content-time">{{ item.startDate }}</div> -->
          <el-divider></el-divider>
        </div>
      </template>
      <el-empty :description="flag?'暂无记录':'暂无待办'" :image-size="100" v-else></el-empty>
    </div>
  </div>
</template>

<script>
import { getMyInstanceList } from "@/api/internalApproval/myApplication.js";
import { getUserTaskPageList } from "@/api/internalApproval/myApproval.js";
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      instanceList: [],
      loading: false,
      flag: true,
    };
  },
  methods: {
    goPage() {
      this.$router.push({
        path: "/approval/internalApproval",
        query: { type: "业务审批", activeName: "third" },
      });
    },
    handleTitle(flag) {
      this.flag = flag;
      if (flag) {
        this.getMyInstanceList();
      } else {
        this.getUserTaskPageList();
      }
    },
    // 获取我发起的流程列表
    async getMyInstanceList() {
      this.loading = true;
      const result = await getMyInstanceList({
        ...this.queryParams,
      });
      this.loading = false;
      this.instanceList = result.data.list;
    },
    // 获取待办任务列表
    async getUserTaskPageList() {
      this.loading = true;
      const result = await getUserTaskPageList({
        ...this.queryParams,
      });
      this.instanceList = result.data.list;
      this.loading = false;
    },
    addClass(activeName) {
      switch (activeName) {
        case 0:
          return "type-pending";
        case 1:
          return "type-pending";
        case 2:
          return "type-approve";
        case 3:
          return "type-reject";
        case 4:
          return "type-revoke";
        case 5:
          return "type-pass";
      }
    },
    //跳转详情
    toDetails(row) {
      this.$router.push({
        path: "/approval/internalApproval",
        query: {
          type: "业务审批",
          activeName: this.flag ? "first" : "second",
          id: row.id,
        },
      });
    },
  },
  mounted() {
    this.getMyInstanceList();
  },
};
</script>

<style lang="scss" scoped>
@function rem($args) {
  @return calc(100vh * #{$args} / 1080);
}

.approval-manage-main {
  height: 100%;
  font-size: rem(20);

  .manage-main-top {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .operate {
      color: #2751d0;
    }
  }

  .manage-main-content {
    height: calc(100% - #{rem(30)});
    padding-top: rem(10);
    overflow: auto;

    .content-item {
      display: flex;
      align-items: center;
      gap: rem(10);
    }

    .content-time {
      margin-top: rem(10);
      text-align: right;
      color: #77819f;
    }

    @mixin common-type($color) {
      width: rem(80);
      height: rem(30);
      text-align: center;
      line-height: rem(30);
      border-radius: rem(3);
      opacity: 1;
      border: 1px solid $color;
      font-size: rem(16);
    }

    .type-revoke {
      background: #d1cece;
      color: #666666;
      @include common-type(#898989);
    }

    .type-pending {
      background: #fff6e7;
      color: #bb8232;
      @include common-type(#d68c46);
    }

    .type-pass {
      background: #cbead5;
      color: #2b5729;
      @include common-type(#6c906b);
    }

    .type-reject {
      background: #f4d1d1;
      color: #b31010;
      @include common-type(#d64646);
    }

    .type-approve {
      background: #d9e3fc;
      color: #3e5cb5;
      @include common-type(#789cd9);
    }
  }
}

::v-deep .el-divider {
  background-color: #d8d8d8;
}

::v-deep .el-divider--horizontal {
  margin: rem(10) 0;
}
::v-deep .el-button--medium {
  padding-top: 0 !important;
}
</style>